<%--
  Created by IntelliJ IDEA.
  User: 王健兵
  Date: 2021/5/15
  Time: 22:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    double m1= 0.0;
    double n1=0.0;
    double sum=0.0;
    String m=request.getParameter("m");
    String n=request.getParameter("n");
    String t=request.getParameter("t");

    String errMsg = "";
    String chu="";
    try{
        if(m!=null && n!=null){
            m1=Double.parseDouble(m);
            n1=Double.parseDouble(n);
        }else{
            m="0.0";n="0.0";
        }
        if("+".equals(t)){
            sum=m1+n1;
        }else if("-".equals(t)){
            sum=m1-n1;
        }
        else if("*".equals(t)){
            sum=m1*n1;
        } else if("/".equals(t)){
            sum=m1/n1;
        }
    }
    catch(NumberFormatException e){
        errMsg = "请输入正确的数值！";
    }catch(ArithmeticException e){
        if(n1==0.0)
            chu="Infinity";
    }
%>

<html>
<head>
    <base href="<%=basePath%>">
    <title>My JSP 'Wyc02.jsp' starting page</title>
</head>
<body>
<form action="<%=basePath%>Calculator.jsp">
    <input type="text" name ="m" placeholder="<%=m %>" >

    <select name="t" >
        <option>+</option>
        <option>-</option>
        <option>*</option>
        <option>/</option>
    </select>
    <input type="text" name ="n" placeholder="<%=n %>">
    <input type="submit" name="tj" value="="><%=sum %>
</form>
</body>
</html>